// createRouter：创建路由实例对象
// createWebHistory：创建History模式的路由
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList  from '@/views/CartList/index.vue'
import Checkout from '@/views/Checkout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import Member from '@/views/Member/index.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 配置path和component对应关系
  routes: [
    {
      path: '/',
      // name: 'layout',
      component: Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'cartlist',
          component: CartList
        },
        {
          path: 'checkout',
          component: Checkout
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'paycallback', // 这个地址是以跳转的为主，不是随便写的（paycallback）
          component: PayBack
        },
        {
          path: 'member',
          component: Member,
          children: [
            {
              path: '',  // 需求：二级路由显示的时候将三级路由默认显示出来，可以将三级路由制空即可。
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    }
  ],
  // 路由行为配置项（当我们将二级路由滚动条拉下来，这个时候我们在切换到一级路由，
  // 我们发现滚动条还是在刚才的位置，我们希望的是点一级路由的时候滚动条重置到顶部）
  scrollBehavior (){
    return {
      top: 0
    }
  }
})

export default router
